import { getPmLevel, setPmLevel } from '../../api/level'


Page({
  data: {
    sleft: "100",
    srig: "110",
    aleft: '90',
    arig: '100',
    bleft: '80',
    brig: '90',
    cleft: '60',
    crig: '80',
    dleft: '0',
    drig: '60'
  },
  onLoad() {
    this.getPmLevel()
  },
  // 查询绩效等级
  getPmLevel() {
    getPmLevel().then((res) => {
      console.log(res.data);
      res.data.forEach((item) => {
        console.log(item.pmLevelName);
        if (item.pmLevelName == 'S') {
          this.setData({
            sleft: item.pmLevelLowValue,
            srig: item.pmLevelHighValue
          })
        } else if (item.pmLevelName == 'A') {
          this.setData({
            aleft: item.pmLevelLowValue,
            arig: item.pmLevelHighValue
          })
        } else if (item.pmLevelName == 'B') {
          this.setData({
            bleft: item.pmLevelLowValue,
            brig: item.pmLevelHighValue
          })
        } else if (item.pmLevelName == 'C') {
          this.setData({
            cleft: item.pmLevelLowValue,
            crig: item.pmLevelHighValue
          })
        } else if (item.pmLevelName == 'D') {
          this.setData({
            dleft: item.pmLevelLowValue,
            drig: item.pmLevelHighValue
          })
        }
      })
    })
  },
  changesLeft(value) {
    this.setData({
      sleft: value
    })
  },
  changeaLeft(value) {
    this.setData({
      aleft: value
    })
  },
  changebLeft(value) {
    this.setData({
      bleft: value
    })
  },
  changecLeft(value) {
    this.setData({
      cleft: value
    })
  },
  changedLeft(value) {
    this.setData({
      dleft: value
    })
  },
  changesRig(value) {
    this.setData({
      srig: value
    })
  },
  changeaRig(value) {
    this.setData({
      arig: value
    })
  },
  changebRig(value) {
    this.setData({
      brig: value
    })
  },
  changecRig(value) {
    this.setData({
      crig: value
    })
  },
  changedRig(value) {
    this.setData({
      drig: value
    })
  },
  // 提交
  submit() {
    let data = [
      {
        pmLevelName: "S",
        sort: 1,
        pmLevelHighValue: this.data.srig,
        pmLevelLowValue: this.data.sleft
      },
      {
        pmLevelName: "A",
        sort: 2,
        pmLevelHighValue: this.data.arig,
        pmLevelLowValue: this.data.aleft
      },
      {
        pmLevelName: "B",
        sort: 3,
        pmLevelHighValue: this.data.brig,
        pmLevelLowValue: this.data.bleft
      },
      {
        pmLevelName: "C",
        sort: 4,
        pmLevelHighValue: this.data.crig,
        pmLevelLowValue: this.data.cleft
      },
      {
        pmLevelName: "D",
        sort: 5,
        pmLevelHighValue: this.data.drig,
        pmLevelLowValue: this.data.dleft
      }
    ]
    console.log(data);
    setPmLevel(JSON.stringify(data)).then((res) => {
      console.log('提交成功');
      dd.showToast({
        content: "提交成功",
        type: "success"
      })
      this.getPmLevel()
    }).catch((err) => {
      dd.showToast({
        content: "提交失败",
        type: "fail"
      })
    })
  },
  // 重置
  clear() {
    this.setData({
      sleft: '',
      srig: '',
      aleft: '',
      arig: '',
      bleft: '',
      brig: '',
      cleft: '',
      crig: '',
      dleft: '',
      drig: ''
    })

  },
});
